package cn.ytnet.shangyun.service.basic.entity;

import org.springframework.stereotype.Component;

import javax.persistence.*;

/**
 * Created by cyongk on 2015/12/8.
 * ClassName：UserEntity
 * ChineseName：系统用户类
 */
@Component("userEntity")
@Entity
@Table(name = "T_User", schema = "crebas", catalog = "")
public class UserEntity {
    private String pkTUserId;
    private String userName;
    private int businessNature;
    private String responsiblePerson;
    private String userAddress;
    private String userPassword;

    private ProvinceEntity provinceEntity;//省（直辖市）
    private CityEntity cityEntity;//市（地区、城市）
    private CountyEntity countyEntity;//县（区）
    private TownEntity townEntity;//镇（乡）

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_province_id")
    public ProvinceEntity getProvinceEntity() {
        return provinceEntity;
    }

    public void setProvinceEntity(ProvinceEntity provinceEntity) {
        this.provinceEntity = provinceEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_city_id")
    public CityEntity getCityEntity() {
        return cityEntity;
    }

    public void setCityEntity(CityEntity cityEntity) {
        this.cityEntity = cityEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_county_id")
    public CountyEntity getCountyEntity() {
        return countyEntity;
    }

    public void setCountyEntity(CountyEntity countyEntity) {
        this.countyEntity = countyEntity;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "pk_t_town_id")
    public TownEntity getTownEntity() {
        return townEntity;
    }

    public void setTownEntity(TownEntity townEntity) {
        this.townEntity = townEntity;
    }

    @Id
    @Column(name = "pk_t_user_id", nullable = false, length = 13)
    public String getPkTUserId() {
        return pkTUserId;
    }

    public void setPkTUserId(String pkTUserId) {
        this.pkTUserId = pkTUserId;
    }

    @Basic
    @Column(name = "user_name", nullable = false, length = 100)
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Basic
    @Column(name = "business_nature", nullable = false)
    public int getBusinessNature() {
        return businessNature;
    }

    public void setBusinessNature(int businessNature) {
        this.businessNature = businessNature;
    }

    @Basic
    @Column(name = "responsible_person", nullable = true, length = 8)
    public String getResponsiblePerson() {
        return responsiblePerson;
    }

    public void setResponsiblePerson(String responsiblePerson) {
        this.responsiblePerson = responsiblePerson;
    }

    @Basic
    @Column(name = "user_address", nullable = false, length = 100)
    public String getUserAddress() {
        return userAddress;
    }

    public void setUserAddress(String userAddress) {
        this.userAddress = userAddress;
    }

    @Basic
    @Column(name = "user_password", nullable = false, length = 100)
    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UserEntity that = (UserEntity) o;

        if (businessNature != that.businessNature) return false;
        if (pkTUserId != null ? !pkTUserId.equals(that.pkTUserId) : that.pkTUserId != null) return false;
        if (userName != null ? !userName.equals(that.userName) : that.userName != null) return false;
        if (responsiblePerson != null ? !responsiblePerson.equals(that.responsiblePerson) : that.responsiblePerson != null)
            return false;
        if (userAddress != null ? !userAddress.equals(that.userAddress) : that.userAddress != null) return false;
        return userPassword != null ? userPassword.equals(that.userPassword) : that.userPassword == null;

    }

    @Override
    public int hashCode() {
        int result = pkTUserId != null ? pkTUserId.hashCode() : 0;
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + businessNature;
        result = 31 * result + (responsiblePerson != null ? responsiblePerson.hashCode() : 0);
        result = 31 * result + (userAddress != null ? userAddress.hashCode() : 0);
        result = 31 * result + (userPassword != null ? userPassword.hashCode() : 0);
        return result;
    }
}
